package controller

import (
	"context"
	pb "gitee.com/micro-services/protocol/room/api"
	"micro.room.client/ao"
)

type RoomDevice struct{}

func (rd *RoomDevice) CreateRoomDevice(ctx context.Context, r *pb.APICreateRoomDeviceReq, w *pb.APICreateRoomDeviceRsp) error {
	rsp, err := ao.CreateRoomDevice(ctx, r)
	if err != nil {
		return err
	}

	w.Msg = rsp.Msg
	w.RetCode = rsp.RetCode
	return nil
}

func (rd *RoomDevice) UpdateRoomDeviceInfo(ctx context.Context, r *pb.APIUpdateRoomDeviceInfoReq, w *pb.APIUpdateRoomDeviceInfoRsp) error {
	rsp, err := ao.UpdateRoomDeviceInfo(ctx, r)
	if err != nil {
		return err
	}

	w.Msg = rsp.Msg
	w.RetCode = rsp.RetCode
	return nil
}

func (rd *RoomDevice) DeleteRoomDevice(ctx context.Context, r *pb.APIDeleteRoomDeviceReq, w *pb.APIDeleteRoomDeviceRsp) error {
	rsp, err := ao.DeleteRoomDevice(ctx, r)
	if err != nil {
		return err
	}

	w.Msg = rsp.Msg
	w.RetCode = rsp.RetCode
	return nil
}

func (rd *RoomDevice) SearchRoomDevice(ctx context.Context, r *pb.APISearchRoomDeviceReq, w *pb.APISearchRoomDeviceRsp) error {
	rsp, err := ao.SearchRoomDevice(ctx, r)
	if err != nil {
		return err
	}

	w.List = rsp.List
	w.Count = rsp.Count
	return nil
}

func (rd *RoomDevice) DeviceList(ctx context.Context, r *pb.APIDeviceListReq, w *pb.APIDeviceListRsp) error {
	rsp, err := ao.DeviceList(ctx, r)
	if err != nil {
		return err
	}

	w.List = rsp.List
	return nil
}
